Expand description

OpenTelemetry is a collection of tools, APIs, and SDKs. Use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) to help you analyze your software’s performance and behavior.

Getting Started

use opentelemetry_api::{global, trace::{Tracer, TracerProvider as _}};
use opentelemetry_sdk::trace::TracerProvider;

fn main() {
    // Choose an exporter like `opentelemetry_stdout::SpanExporter`
    let exporter = new_exporter();

    // Create a new trace pipeline that prints to stdout
    let provider = TracerProvider::builder()
        .with_simple_exporter(exporter)
        .build();
    let tracer = provider.tracer("readme_example");

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    // Shutdown trace pipeline
    global::shutdown_tracer_provider();
}

See the examples directory for different integration patterns.

See the API trace module docs for more information on creating and managing spans.

Metrics (Beta)

Note: the metrics implementation is still in progress and subject to major changes.

Creating instruments and recording measurements

use opentelemetry_api::{global, KeyValue};

// get a meter from a provider
let meter = global::meter("my_service");

// create an instrument
let counter = meter.u64_counter("my_counter").init();

// record a measurement
counter.add(1, &[KeyValue::new("http.client_ip", "83.164.160.102")]);

See the examples directory for different integration patterns.

See the API metrics module docs for more information on creating and managing instruments.

Crate Feature Flags

The following core crate feature flags are available:

  • trace: Includes the trace SDK (enabled by default).
  • metrics: Includes the unstable metrics SDK.

Support for recording and exporting telemetry asynchronously can be added via the following flags:

  • rt-tokio: Spawn telemetry tasks using tokio’s multi-thread runtime.
  • rt-tokio-current-thread: Spawn telemetry tasks on a separate runtime so that the main runtime won’t be blocked.
  • rt-async-std: Spawn telemetry tasks using async-std’s runtime.

Modules

  • Telemetry Export
  • logslogs
    OpenTelemetry Log SDK
  • metricsmetrics
    The rust of the OpenTelemetry metrics SDK.
  • OpenTelemetry Propagators
  • Representations of entities producing telemetry.
  • Provides an abstraction of several async runtimes
  • tracetrace
    OpenTelemetry Trace SDK

Structs

  • A unique set of attributes that can be used as instrument identifiers.
  • Information about a library or crate providing instrumentation.
  • An immutable representation of the entity producing telemetry as attributes.

Type Definitions

  • A logical unit of the application code with which the emitted telemetry can be associated.